﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

namespace mpsalaryprojectgroup
{
    public partial class NEWNEWReport : System.Web.UI.Page
    {
        String username = "";
        String loginName = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["Usename"] != null)
            {
                username = (string)(Session["Usename"]);
                if (username == null)
                {
                    Response.Redirect("NEWMainPage.aspx");
                }
                else
                {
                    lblUsername.Text = username;
                }
            }
            else if (Session["UsenameLogin"] != null)
            {
                loginName = (string)(Session["UsenameLogin"]);
                if (loginName == null)
                {
                    Response.Redirect("NEWMainPage.aspx");
                }
                else
                {
                    lblUsername.Text = loginName;
                }
            }
            else
            {
                Response.Redirect("NEWMainPage.aspx");
            }
            DisableBufferingOnPage();
        }
        protected void DisableBufferingOnPage()
        {
            Response.Buffer = true;
            Response.ExpiresAbsolute = DateTime.Now.AddDays(-1);
            // set expiry date in the past
            Response.Expires = -1;
            Response.CacheControl = "no-cache";
            Response.Cache.SetNoStore();
            Response.AppendHeader("Pragma", "no-cache");
            Response.AppendHeader("Cache-Control", "no-cache");
            Response.CacheControl = "no-cache";
            Response.Expires = -1;
            Response.ExpiresAbsolute = new DateTime(1900, 1, 1);
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
        }


        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string a = ddlistYear.SelectedValue;
            string dataString = "Server=.;Database=PGSPORTAL;Trusted_Connection=true"; //Data Source must change because of different computer names! //Janee\\sqlexpress
            SqlConnection sqlConnection = new SqlConnection(dataString);
            sqlConnection.Open();
            SqlCommand sqlCommand;

            if (tbxSearch.Text != "")
            {
                sqlCommand = new SqlCommand("select * from [Wages] WHERE Year = " + ddlistYear.SelectedValue + " AND Course LIKE '%" + tbxSearch.Text + "%'AND PolyConducting LIKE '%" + ddlSchool.SelectedValue + "%'");
            }
            else
            {
                sqlCommand = new SqlCommand("select * from [Wages] WHERE Year = " + ddlistYear.SelectedValue + " AND Course LIKE '%" + ddlCourseGroup.SelectedValue + "%'AND PolyConducting LIKE '%" + ddlSchool.SelectedValue + "%'");
            }
            sqlCommand.Connection = sqlConnection;
            SqlDataReader dr = sqlCommand.ExecuteReader();

            GridView1.DataSource = dr;
            GridView1.DataBind();
            lblReturnNoResults.Visible = false;

            if (GridView1.Rows.Count == 0)
            {
                GridView1.Visible = false;
                lblReturnNoResults.Visible = true;
                lblReturnNoResults.Text = "Your search returned no results.";
            }
            else
                GridView1.Visible = true;
            


        }

        protected void btnReset_Click(object sender, EventArgs e)
        {
            ddlistYear.ClearSelection();
            ddlSchool.ClearSelection();
            ddlCourseGroup.ClearSelection();
            GridView1.Visible = false;
            
        }

        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.Header)
            {
                e.Row.Cells[0].Text = "Year";
                e.Row.Cells[1].Text = "Course";
                e.Row.Cells[2].Text = "Schools";
                e.Row.Cells[3].Text = "Employment Number of Fresh Graduates";
                e.Row.Cells[4].Text = "Employment Rate of Fresh Graduates";
                e.Row.Cells[5].Text = "Monthly Mean of Fresh Graduates";
                e.Row.Cells[6].Text = "Monthly Median of Fresh Graduates";
                e.Row.Cells[7].Text = "Employment Number of Post Graduates";
                e.Row.Cells[8].Text = "Employment Rate of Post Graduates";
                e.Row.Cells[9].Text = "Monthly Mean of Post Graduates";
                e.Row.Cells[10].Text = "Monthly Median of Post Graduates";
                e.Row.Cells[11].Text = "Industrial Area";

            }
        }

        protected void ddlistYear_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        protected void btnProceed_Click(object sender, EventArgs e)
        {
            Response.Redirect("NEWNEWReportUser.aspx");
        }

    }
}